package com.jerry.roomdemo;

import android.os.Bundle;
import android.util.Log;

import com.alibaba.fastjson.JSONObject;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.jerry.libnetwork.ApiResponse;
import com.jerry.libnetwork.GetRequest;
import com.jerry.libnetwork.JsonCallback;
import com.jerry.roomdemo.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        BottomNavigationView navView = findViewById(R.id.nav_view);
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(binding.navView, navController);

        GetRequest<JSONObject> request = new GetRequest<>("http://www.baidu.com");
//        ApiResponse<JSONObject> response = request
//                .responseType()
//                .execute();
//        Log.e(TAG, "同步返回: " + response);

        request.execute(new JsonCallback() {
            @Override
            public void onSuccess(ApiResponse response) {
                super.onSuccess(response);
                Log.e(TAG, "onSuccess: " + response);
            }

            @Override
            public void onError(ApiResponse response) {
                super.onError(response);
                Log.e(TAG, "onError: " + response);
            }
        });
    }

}